package com.superhelper.common.domain;

import java.util.Map;

import org.apache.commons.lang3.StringUtils;

public enum PushMsgType {
    ORDER_CREATED("order_created", "创建新订单"), ORDER_ACCEPTED("order_accepted", "商家接单"), ORDER_CANCELED("order_canceled",
            "取消订单"), ORDER_REFUND("order_refund", "订单退款"), ORDER_COMPLETED("order_completed",
                    "订单已完成"), ORDER_APPLY_CANCEL("order_apply_cancel", "用户申请取消"), ORDER_REVOKE_CANCEL(
                            "order_revoke_cancel",
                            "用户撤销取消"), ORDER_AGREE_CANCEL("order_agree_cancel", "商家同意取消"), ORDER_REJECT_CANCEL(
                                    "order_reject_cancel",
                                    "商家拒接取消"), DELIVER_EXCEPTION("deliver_exception", "配送异常"), DELIVER_MONEY_EXCEPTION(
                                            "deliver_money_exception",
                                            "配送余额不足请充值"), UNKNOWN("unknown", "未知"), DELIVER_EXPIRE("deliver_expire",
                                                    "配送超时"), DELIVER_STATUS("deliver_status", "配送状态"), POI_STATUS(
                                                            "poi_status", "门店状态变更"), ORDER_REVOKE_REFUND(
                                                                    "order_revoke_refund", "用户撤销退款");
    private String value;
    private String desc;

    public String getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }

    private PushMsgType(String value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    public static PushMsgType getByEleType(int type) {
        switch (type) {
        case 10:
            return ORDER_CREATED;
        case 12:
            return ORDER_ACCEPTED;
        case 14:
            return ORDER_CANCELED;
        case 15:
            return ORDER_AGREE_CANCEL;
        case 17:
            return ORDER_CANCELED;
        case 18:
            return ORDER_COMPLETED;
        case 20:
            return ORDER_APPLY_CANCEL;
        case 31:
            return ORDER_REVOKE_REFUND;
        case 21:
            return ORDER_REVOKE_CANCEL;
        case 22:
        case 32:
            return ORDER_REJECT_CANCEL;
        case 23:
        case 33:
            return ORDER_AGREE_CANCEL;
        case 30:
            return ORDER_REFUND;
        case 51:
        case 52:
        case 53:
        case 54:
        case 55:
        case 56:
            return DELIVER_STATUS;
        case 91:
            return POI_STATUS;
        default:
            return UNKNOWN;
        }
    }

    public static PushMsgType getByBdType(String cmd, Map<String, Object> body) {
        switch (cmd) {
        case "order.create":
            return ORDER_CREATED;
        case "order.status.push":
            String status = String.valueOf(body.get("status"));
            if ("5".equals(status)) {
                return ORDER_ACCEPTED;
            } else if ("9".equals(status)) {
                return ORDER_COMPLETED;
            } else if ("10".equals(status)) {
                return ORDER_CANCELED;
            } else if ("7".equals(status) || "8".equals(status)) {
                return DELIVER_STATUS;
            }
        case "order.partrefund.push":
            status = (String) body.get("status");
            return ORDER_CANCELED;
        case "shop.status.push":
            return POI_STATUS;
        default:
            return UNKNOWN;
        }
    }

    public static PushMsgType getByMtType(String type) {
        for (PushMsgType p : PushMsgType.values()) {
            if (StringUtils.equalsIgnoreCase(p.getValue(), type)) {
                return p;
            }
        }
        return UNKNOWN;
    }
}
